<template>
  <!--  修改信息 -->
  <el-dialog
    width="500px"
    title="修改信息"
    destroy-on-close
    append-to-body
    :visible.sync="show"
    :before-close="cancel"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <!-- 租户类型 租户id 租户名称 用户名 用户角色 状态 最后登录时间 最后登录IP  -->
      <el-form-item label="租户类型" prop="userName">
        <el-input v-model="form.userName" />
      </el-form-item>
      <el-form-item label="租户id" prop="userName">
        <el-input v-model="form.userName" />
      </el-form-item>
      <el-form-item label="租户名称" prop="userName">
        <el-input v-model="form.userName" />
      </el-form-item>
      <el-form-item label="用户名" prop="userName">
        <el-input v-model="form.userName" />
      </el-form-item>
      <el-form-item label="用户角色" prop="userName">
        <el-input v-model="form.userName" />
      </el-form-item>
      <el-form-item label="状态" prop="userName">
        <el-input v-model="form.userName" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="handleSubmit">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  activated() {
    this.$nextTick(() => this.$refs['TableRef']?.doLayout())
  },
  props: {
    /**
     * formData
     */
    formData: {
      type: Object,
      default: {},
    },
    /**
     * type
     */
    type: {
      type: String,
      default: "add",
    },
    /**
     * 控制显示隐藏
     */
    show: {
      type: Boolean,
      required: true,
      default: false,
    },
  },
  data() {
    return {
      form: {},
      // 表单校验
      rules: {
        userName: [
          { required: true, message: "用户名称不能为空", trigger: "blur" },
        ],
      },
    };
  },
  computed: {},
  watch: {
    show: function (newValue) {
      if (newValue) {
        this.resetForm();
        if (this.type == "edit") {
          Object.keys(this.formData).forEach((key) => {
            this.form[key] = this.formData[key];
          });
          console.log(`this.form ==>`, JSON.parse(JSON.stringify(this.form)));
        }
      }
    },
  },
  methods: {
    handleSubmit() {},
    resetForm() {
      Object.keys(this.form).forEach((key) => (this.form[key] = ""));
    },

    cancel() {
      this.$emit("update:show", false);
    },
  },
};
</script>
<style scoped lang="scss"></style>
